function fixImage(img, w, h) {
    var newImg = new Image();
    newImg.src = img.src;
    var lh;  
    if (newImg.width/newImg.height >= w/h) {
        if (newImg.width > w) {
            img.width = w;
            img.height = w * newImg.height / newImg.width;
            lh = window.ActiveXObject ? parseInt(img.currentStyle['height']) : img.height;
            img.style.marginTop = (h - lh)/2 + 'px';
        } else {
            img.width = newImg.width;
            img.height = newImg.height;
            lh = window.ActiveXObject ? parseInt(img.currentStyle['height']) : img.height;
            img.style.marginTop = (h - lh)/2 + 'px';
        }
    } else {
        if (newImg.height > h) {
            img.height = h;
            img.width = newImg.width * h / newImg.height;
        } else {
            img.width = newImg.width;
            img.height = newImg.height;
        }
    }
}